package com.zhuanghdong.controller;

import com.zhuanghdong.pojo.PortalVo;
import com.zhuanghdong.pojo.Type;
import com.zhuanghdong.service.HeadlineService;
import com.zhuanghdong.service.TypeService;
import com.zhuanghdong.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 首页模块开发
 * 功能分类包括：查询首页分类
 *            分页查询首页头条信息
 *            查询头条详情
 */
@RestController
@RequestMapping("portal")
@CrossOrigin
public class PortalController {
    @Autowired
    private TypeService typeService;

    @Autowired
    private HeadlineService headlineService;

    /**
     * 查询首页分类信息
     * @return result
     */
    @GetMapping("findAllTypes")
    public Result findAllTypes(){
        //直接调用业务层,查询全部数据
        List<Type> list=typeService.list();
        return Result.ok(list);
    }

    /**
     * 分页查询首页头条信息
     * @param portalVo
     * @return result
     */
    @PostMapping("findNewsPage")
    public Result findNewsPage(@RequestBody PortalVo portalVo){
        Result result=headlineService.findNewPage(portalVo);
        return result;
    }

    /**
     * 查询头条详情:
     * 根据头条hid来查询该头条内容的id信息
     * @param hid
     * @return  result
     */
    @PostMapping("showHeadlineDetail")
    public Result showHeadlineDetail(Integer hid){
        Result result = headlineService.showHeadlineDetail(hid);
        return result;
    }
}
